from google.appengine.ext import webapp
from DataClass.WebsiteRec import WebsiteRec
from DataClass.FullPage import FullPage
from google.appengine.api import users
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from AdminBase import AdminBase

import os
import cgi

class DeletePageHandler(AdminBase):
    def GetTemplateFileName(self):
        return 'Pages/deletepage.html'
        
    def GetBreadcrumbList(self):
        return [['main', 'admin'],['pages', 'editpages'],['delete page']]
    
    def GetTemplateValuesDict(self, template_values, user):
        retval = template_values

        Website = template_values['currentwebsite']

        querystring=cgi.FieldStorage()
        pagename=querystring.getvalue('pagename')
        
        Page = FullPage.GetPageBySiteNameAndPageName(Website.sitename, pagename)
    
        if Page:
            retval['page'] = Page
    
        return retval

    def DoPost(self, user):
        sitename = self.request.get('sitename')
        pagename = self.request.get('pagename')

        Page = FullPage.GetPageBySiteNameAndPageName(sitename, pagename)

        if Page:
            db.delete(Page)

        self.redirect('/editpages')


